<!-- HTML header for doxygen 1.8.20-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=9"/>
	<meta name="generator" content="Doxygen 1.9.4"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Raspberry Pi Pico SDK: include/hardware/adc.h Source File</title>
	<!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="dynsections.js"></script>
	<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
	<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
	<link href="doxygen.css" rel="stylesheet" type="text/css" />
	<link href="normalise.css" rel="stylesheet" type="text/css"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div class="navigation-mobile">
		<div class="logo--mobile">
			<a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
		</div>
		<div class="navigation-toggle">
			<span class="line-1"></span>
			<span class="line-2">
				<p>Menu Toggle</p>
			</span>
			<span class="line-3"></span>
		</div>
	</div>
	<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
		<div class="logo">
			<a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
			<span style="display: inline-block; margin-top: 10px;">
				v2.1.0
			</span>
		</div>
		<div class="navigation-footer">
			<img src="logo-mobile.svg" alt="Raspberry Pi">
			<a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
		</div>
<!-- 		<div class="search">
			<form>
				<input type="search" name="search" id="search" placeholder="Search">
				<input type="submit" value="Search">
			</form>
		</div> -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('rp2__common_2hardware__adc_2include_2hardware_2adc_8h_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle"><div class="title">adc.h</div></div>
</div><!--header-->
<div class="contents">
<a href="rp2__common_2hardware__adc_2include_2hardware_2adc_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span><span class="comment">/*</span></div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno">    2</span><span class="comment"> * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.</span></div>
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno">    3</span><span class="comment"> *</span></div>
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno">    4</span><span class="comment"> * SPDX-License-Identifier: BSD-3-Clause</span></div>
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno">    5</span><span class="comment"> */</span></div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno">    6</span> </div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno">    7</span><span class="preprocessor">#ifndef _HARDWARE_ADC_H</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno">    8</span><span class="preprocessor">#define _HARDWARE_ADC_H</span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span> </div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span><span class="preprocessor">#include &quot;<a class="code" href="pico_8h.html">pico.h</a>&quot;</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#include &quot;hardware/structs/adc.h&quot;</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="preprocessor">#include &quot;<a class="code" href="gpio_8h.html">hardware/gpio.h</a>&quot;</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span> </div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span><span class="comment">// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_HARDWARE_ADC, Enable/disable assertions in the hardware_adc module, type=bool, default=0, group=hardware_adc</span></div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span><span class="preprocessor">#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_ADC</span></div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno">   59</span><span class="preprocessor">#ifdef PARAM_ASSERTIONS_ENABLED_ADC </span><span class="comment">// backwards compatibility with SDK &lt; 2.0.0</span></div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span><span class="preprocessor">#define PARAM_ASSERTIONS_ENABLED_HARDWARE_ADC PARAM_ASSERTIONS_ENABLED_ADC</span></div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span><span class="preprocessor">#else</span></div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span><span class="preprocessor">#define PARAM_ASSERTIONS_ENABLED_HARDWARE_ADC 0</span></div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno">   65</span> </div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno">   69</span><span class="preprocessor">#ifndef ADC_TEMPERATURE_CHANNEL_NUM</span></div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"><a class="line" href="rp2__common_2hardware__adc_2include_2hardware_2adc_8h.html#a9622105dbe8b3d37a5118dab13c551e9">   70</a></span><span class="preprocessor">#define ADC_TEMPERATURE_CHANNEL_NUM (NUM_ADC_CHANNELS - 1)</span></div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno">   71</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span> </div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span><span class="comment">// PICO_CONFIG: PICO_ADC_CLKDIV_ROUND_NEAREST, True if floating point ADC clock divisors should be rounded to the nearest possible clock divisor rather than rounding down, type=bool, default=PICO_CLKDIV_ROUND_NEAREST, group=hardware_adc</span></div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span><span class="preprocessor">#ifndef PICO_ADC_CLKDIV_ROUND_NEAREST</span></div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span><span class="preprocessor">#define PICO_ADC_CLKDIV_ROUND_NEAREST PICO_CLKDIV_ROUND_NEAREST</span></div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span> </div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span><span class="preprocessor">#ifdef __cplusplus</span></div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span> </div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span><span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#ga2b815e6730e8723a6d1d06d9ef8f31c0">adc_init</a>(<span class="keywordtype">void</span>);</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span> </div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#gab15d6e804715935b4e9b5027a2940910">   95</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#gab15d6e804715935b4e9b5027a2940910">adc_gpio_init</a>(uint gpio) {</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span>    invalid_params_if(HARDWARE_ADC, gpio &lt; ADC_BASE_PIN || gpio &gt;= ADC_BASE_PIN + NUM_ADC_CHANNELS - 1);</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span>    <span class="comment">// Select NULL function to make output driver hi-Z</span></div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>    <a class="code hl_function" href="group__hardware__gpio.html#ga22f6b90c4c7e0013b4b5341de0a44fc4">gpio_set_function</a>(gpio, <a class="code hl_enumvalue" href="group__hardware__gpio.html#ggaf91b38a4d4e96c343bd16927c34936e0a3ec115257e1f1747abf60284362c5a04">GPIO_FUNC_NULL</a>);</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span>    <span class="comment">// Also disable digital pulls and digital receiver</span></div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span>    <a class="code hl_function" href="group__hardware__gpio.html#gae57a625b7e0bcac6d596f35864ffc792">gpio_disable_pulls</a>(gpio);</div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span>    <a class="code hl_function" href="group__hardware__gpio.html#ga74a8c3e55185581bc3df335aea1d0fb8">gpio_set_input_enabled</a>(gpio, <span class="keyword">false</span>);</div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span>}</div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno">  103</span> </div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#ga5d3b8875947df2f4ba022cb6aa40594b">  118</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#ga5d3b8875947df2f4ba022cb6aa40594b">adc_select_input</a>(uint input) {</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>    valid_params_if(HARDWARE_ADC, input &lt; NUM_ADC_CHANNELS);</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span>    <a class="code hl_function" href="group__hardware__base.html#ga81b27e30abef56fe090d22fd8dfdbcc1">hw_write_masked</a>(&amp;adc_hw-&gt;cs, input &lt;&lt; ADC_CS_AINSEL_LSB, ADC_CS_AINSEL_BITS);</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>}</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span> </div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#ga84b5f9054de9c00d51095c9bdefb2dca">  137</a></span><span class="keyword">static</span> <span class="keyword">inline</span> uint <a class="code hl_function" href="group__hardware__adc.html#ga84b5f9054de9c00d51095c9bdefb2dca">adc_get_selected_input</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno">  138</span>    <span class="keywordflow">return</span> (adc_hw-&gt;cs &amp; ADC_CS_AINSEL_BITS) &gt;&gt; ADC_CS_AINSEL_LSB;</div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno">  139</span>}</div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno">  140</span> </div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#ga16d25be75e16f0671d3e3185b0b59771">  150</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#ga16d25be75e16f0671d3e3185b0b59771">adc_set_round_robin</a>(uint input_mask) {</div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno">  151</span>    valid_params_if(HARDWARE_ADC, input_mask &lt; (1 &lt;&lt; NUM_ADC_CHANNELS));</div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno">  152</span>    <a class="code hl_function" href="group__hardware__base.html#ga81b27e30abef56fe090d22fd8dfdbcc1">hw_write_masked</a>(&amp;adc_hw-&gt;cs, input_mask &lt;&lt; ADC_CS_RROBIN_LSB, ADC_CS_RROBIN_BITS);</div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno">  153</span>}</div>
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno">  154</span> </div>
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#ga33f302059e05899d1709d6268d75972b">  161</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#ga33f302059e05899d1709d6268d75972b">adc_set_temp_sensor_enabled</a>(<span class="keywordtype">bool</span> enable) {</div>
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno">  162</span>    <span class="keywordflow">if</span> (enable)</div>
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno">  163</span>        <a class="code hl_function" href="group__hardware__base.html#ga625e737a57f12211cf1f634ca5095ae4">hw_set_bits</a>(&amp;adc_hw-&gt;cs, ADC_CS_TS_EN_BITS);</div>
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno">  164</span>    <span class="keywordflow">else</span></div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno">  165</span>        <a class="code hl_function" href="group__hardware__base.html#gafd1c089df868d987daf95870b501c2ed">hw_clear_bits</a>(&amp;adc_hw-&gt;cs, ADC_CS_TS_EN_BITS);</div>
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno">  166</span>}</div>
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno">  167</span> </div>
<div class="line"><a id="l00175" name="l00175"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#gaf32d82a43103e6672048001f58d5f6fb">  175</a></span><span class="keyword">static</span> <span class="keyword">inline</span> uint16_t <a class="code hl_function" href="group__hardware__adc.html#gaf32d82a43103e6672048001f58d5f6fb">adc_read</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00176" name="l00176"></a><span class="lineno">  176</span>    <a class="code hl_function" href="group__hardware__base.html#ga625e737a57f12211cf1f634ca5095ae4">hw_set_bits</a>(&amp;adc_hw-&gt;cs, ADC_CS_START_ONCE_BITS);</div>
<div class="line"><a id="l00177" name="l00177"></a><span class="lineno">  177</span> </div>
<div class="line"><a id="l00178" name="l00178"></a><span class="lineno">  178</span>    <span class="keywordflow">while</span> (!(adc_hw-&gt;cs &amp; ADC_CS_READY_BITS))</div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno">  179</span>        <a class="code hl_function" href="group__pico__platform.html#gab0d1ba75ceb64131e19f613d7a5313c9">tight_loop_contents</a>();</div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno">  180</span> </div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno">  181</span>    <span class="keywordflow">return</span> (uint16_t) adc_hw-&gt;result;</div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno">  182</span>}</div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno">  183</span> </div>
<div class="line"><a id="l00189" name="l00189"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#ga5d50a24eb26da7fbc6ee9bc76723b09c">  189</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#ga5d50a24eb26da7fbc6ee9bc76723b09c">adc_run</a>(<span class="keywordtype">bool</span> run) {</div>
<div class="line"><a id="l00190" name="l00190"></a><span class="lineno">  190</span>    <span class="keywordflow">if</span> (run)</div>
<div class="line"><a id="l00191" name="l00191"></a><span class="lineno">  191</span>        <a class="code hl_function" href="group__hardware__base.html#ga625e737a57f12211cf1f634ca5095ae4">hw_set_bits</a>(&amp;adc_hw-&gt;cs, ADC_CS_START_MANY_BITS);</div>
<div class="line"><a id="l00192" name="l00192"></a><span class="lineno">  192</span>    <span class="keywordflow">else</span></div>
<div class="line"><a id="l00193" name="l00193"></a><span class="lineno">  193</span>        <a class="code hl_function" href="group__hardware__base.html#gafd1c089df868d987daf95870b501c2ed">hw_clear_bits</a>(&amp;adc_hw-&gt;cs, ADC_CS_START_MANY_BITS);</div>
<div class="line"><a id="l00194" name="l00194"></a><span class="lineno">  194</span>}</div>
<div class="line"><a id="l00195" name="l00195"></a><span class="lineno">  195</span> </div>
<div class="line"><a id="l00204" name="l00204"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#ga333f7ca46a11241d96d0a4c24f0d4bb0">  204</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#ga333f7ca46a11241d96d0a4c24f0d4bb0">adc_set_clkdiv</a>(<span class="keywordtype">float</span> clkdiv) {</div>
<div class="line"><a id="l00205" name="l00205"></a><span class="lineno">  205</span>    invalid_params_if(HARDWARE_ADC, clkdiv &gt;= 1 &lt;&lt; REG_FIELD_WIDTH(ADC_DIV_INT));</div>
<div class="line"><a id="l00206" name="l00206"></a><span class="lineno">  206</span>    <span class="keyword">const</span> <span class="keywordtype">int</span> frac_bit_count = REG_FIELD_WIDTH(ADC_DIV_FRAC);</div>
<div class="line"><a id="l00207" name="l00207"></a><span class="lineno">  207</span><span class="preprocessor">#if PICO_ADC_CLKDIV_ROUND_NEAREST</span></div>
<div class="line"><a id="l00208" name="l00208"></a><span class="lineno">  208</span>    clkdiv += 0.5f / (1 &lt;&lt; frac_bit_count); <span class="comment">// round to the nearest fraction</span></div>
<div class="line"><a id="l00209" name="l00209"></a><span class="lineno">  209</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00210" name="l00210"></a><span class="lineno">  210</span>    adc_hw-&gt;div = (uint32_t)(clkdiv * (<span class="keywordtype">float</span>) (1 &lt;&lt; frac_bit_count));</div>
<div class="line"><a id="l00211" name="l00211"></a><span class="lineno">  211</span>}</div>
<div class="line"><a id="l00212" name="l00212"></a><span class="lineno">  212</span> </div>
<div class="line"><a id="l00232" name="l00232"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#ga2a6fa32da04e65a027e14deaf32b8f10">  232</a></span> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#ga2a6fa32da04e65a027e14deaf32b8f10">adc_fifo_setup</a>(<span class="keywordtype">bool</span> en, <span class="keywordtype">bool</span> dreq_en, uint16_t dreq_thresh, <span class="keywordtype">bool</span> err_in_fifo, <span class="keywordtype">bool</span> byte_shift) {</div>
<div class="line"><a id="l00233" name="l00233"></a><span class="lineno">  233</span>    <a class="code hl_function" href="group__hardware__base.html#ga81b27e30abef56fe090d22fd8dfdbcc1">hw_write_masked</a>(&amp;adc_hw-&gt;fcs,</div>
<div class="line"><a id="l00234" name="l00234"></a><span class="lineno">  234</span>                   (bool_to_bit(en) &lt;&lt; ADC_FCS_EN_LSB) |</div>
<div class="line"><a id="l00235" name="l00235"></a><span class="lineno">  235</span>                   (bool_to_bit(dreq_en) &lt;&lt; ADC_FCS_DREQ_EN_LSB) |</div>
<div class="line"><a id="l00236" name="l00236"></a><span class="lineno">  236</span>                   (((uint)dreq_thresh) &lt;&lt; ADC_FCS_THRESH_LSB) |</div>
<div class="line"><a id="l00237" name="l00237"></a><span class="lineno">  237</span>                   (bool_to_bit(err_in_fifo) &lt;&lt; ADC_FCS_ERR_LSB) |</div>
<div class="line"><a id="l00238" name="l00238"></a><span class="lineno">  238</span>                   (bool_to_bit(byte_shift) &lt;&lt; ADC_FCS_SHIFT_LSB),</div>
<div class="line"><a id="l00239" name="l00239"></a><span class="lineno">  239</span>                   ADC_FCS_EN_BITS |</div>
<div class="line"><a id="l00240" name="l00240"></a><span class="lineno">  240</span>                   ADC_FCS_DREQ_EN_BITS |</div>
<div class="line"><a id="l00241" name="l00241"></a><span class="lineno">  241</span>                   ADC_FCS_THRESH_BITS |</div>
<div class="line"><a id="l00242" name="l00242"></a><span class="lineno">  242</span>                   ADC_FCS_ERR_BITS |</div>
<div class="line"><a id="l00243" name="l00243"></a><span class="lineno">  243</span>                   ADC_FCS_SHIFT_BITS</div>
<div class="line"><a id="l00244" name="l00244"></a><span class="lineno">  244</span>    );</div>
<div class="line"><a id="l00245" name="l00245"></a><span class="lineno">  245</span>}</div>
<div class="line"><a id="l00246" name="l00246"></a><span class="lineno">  246</span> </div>
<div class="line"><a id="l00252" name="l00252"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#gafdfd586e6c26ffe4759afaa3c3f95465">  252</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code hl_function" href="group__hardware__adc.html#gafdfd586e6c26ffe4759afaa3c3f95465">adc_fifo_is_empty</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00253" name="l00253"></a><span class="lineno">  253</span>    <span class="keywordflow">return</span> adc_hw-&gt;fcs &amp; ADC_FCS_EMPTY_BITS;</div>
<div class="line"><a id="l00254" name="l00254"></a><span class="lineno">  254</span>}</div>
<div class="line"><a id="l00255" name="l00255"></a><span class="lineno">  255</span> </div>
<div class="line"><a id="l00268" name="l00268"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#gafa9793deea59c5cbfea147e0e9d895c3">  268</a></span><span class="keyword">static</span> <span class="keyword">inline</span> uint8_t <a class="code hl_function" href="group__hardware__adc.html#gafa9793deea59c5cbfea147e0e9d895c3">adc_fifo_get_level</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00269" name="l00269"></a><span class="lineno">  269</span>    <span class="keywordflow">return</span> (adc_hw-&gt;fcs &amp; ADC_FCS_LEVEL_BITS) &gt;&gt; ADC_FCS_LEVEL_LSB;</div>
<div class="line"><a id="l00270" name="l00270"></a><span class="lineno">  270</span>}</div>
<div class="line"><a id="l00271" name="l00271"></a><span class="lineno">  271</span> </div>
<div class="line"><a id="l00277" name="l00277"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#ga689d64744e7fe5284562569b24e9d624">  277</a></span><span class="keyword">static</span> <span class="keyword">inline</span> uint16_t <a class="code hl_function" href="group__hardware__adc.html#ga689d64744e7fe5284562569b24e9d624">adc_fifo_get</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00278" name="l00278"></a><span class="lineno">  278</span>    <span class="keywordflow">return</span> (uint16_t)adc_hw-&gt;fifo;</div>
<div class="line"><a id="l00279" name="l00279"></a><span class="lineno">  279</span>}</div>
<div class="line"><a id="l00280" name="l00280"></a><span class="lineno">  280</span> </div>
<div class="line"><a id="l00286" name="l00286"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#ga61553375ecc9275fa14c6ff7792a1506">  286</a></span><span class="keyword">static</span> <span class="keyword">inline</span> uint16_t <a class="code hl_function" href="group__hardware__adc.html#ga61553375ecc9275fa14c6ff7792a1506">adc_fifo_get_blocking</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00287" name="l00287"></a><span class="lineno">  287</span>    <span class="keywordflow">while</span> (<a class="code hl_function" href="group__hardware__adc.html#gafdfd586e6c26ffe4759afaa3c3f95465">adc_fifo_is_empty</a>())</div>
<div class="line"><a id="l00288" name="l00288"></a><span class="lineno">  288</span>        <a class="code hl_function" href="group__pico__platform.html#gab0d1ba75ceb64131e19f613d7a5313c9">tight_loop_contents</a>();</div>
<div class="line"><a id="l00289" name="l00289"></a><span class="lineno">  289</span>    <span class="keywordflow">return</span> (uint16_t)adc_hw-&gt;fifo;</div>
<div class="line"><a id="l00290" name="l00290"></a><span class="lineno">  290</span>}</div>
<div class="line"><a id="l00291" name="l00291"></a><span class="lineno">  291</span> </div>
<div class="line"><a id="l00297" name="l00297"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#gad637d97583f2c24e4159dc22bf17eaf2">  297</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#gad637d97583f2c24e4159dc22bf17eaf2">adc_fifo_drain</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00298" name="l00298"></a><span class="lineno">  298</span>    <span class="comment">// Potentially there is still a conversion in progress -- wait for this to complete before draining</span></div>
<div class="line"><a id="l00299" name="l00299"></a><span class="lineno">  299</span>    <span class="keywordflow">while</span> (!(adc_hw-&gt;cs &amp; ADC_CS_READY_BITS))</div>
<div class="line"><a id="l00300" name="l00300"></a><span class="lineno">  300</span>        <a class="code hl_function" href="group__pico__platform.html#gab0d1ba75ceb64131e19f613d7a5313c9">tight_loop_contents</a>();</div>
<div class="line"><a id="l00301" name="l00301"></a><span class="lineno">  301</span>    <span class="keywordflow">while</span> (!<a class="code hl_function" href="group__hardware__adc.html#gafdfd586e6c26ffe4759afaa3c3f95465">adc_fifo_is_empty</a>())</div>
<div class="line"><a id="l00302" name="l00302"></a><span class="lineno">  302</span>        (void) <a class="code hl_function" href="group__hardware__adc.html#ga689d64744e7fe5284562569b24e9d624">adc_fifo_get</a>();</div>
<div class="line"><a id="l00303" name="l00303"></a><span class="lineno">  303</span>}</div>
<div class="line"><a id="l00304" name="l00304"></a><span class="lineno">  304</span> </div>
<div class="line"><a id="l00310" name="l00310"></a><span class="lineno"><a class="line" href="group__hardware__adc.html#gaf8e363e63f40e00c169f7355c9668681">  310</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="group__hardware__adc.html#gaf8e363e63f40e00c169f7355c9668681">adc_irq_set_enabled</a>(<span class="keywordtype">bool</span> enabled) {</div>
<div class="line"><a id="l00311" name="l00311"></a><span class="lineno">  311</span>    adc_hw-&gt;inte = !!enabled;</div>
<div class="line"><a id="l00312" name="l00312"></a><span class="lineno">  312</span>}</div>
<div class="line"><a id="l00313" name="l00313"></a><span class="lineno">  313</span> </div>
<div class="line"><a id="l00314" name="l00314"></a><span class="lineno">  314</span><span class="preprocessor">#ifdef __cplusplus</span></div>
<div class="line"><a id="l00315" name="l00315"></a><span class="lineno">  315</span>}</div>
<div class="line"><a id="l00316" name="l00316"></a><span class="lineno">  316</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00317" name="l00317"></a><span class="lineno">  317</span> </div>
<div class="line"><a id="l00318" name="l00318"></a><span class="lineno">  318</span><span class="preprocessor">#endif</span></div>
<div class="ttc" id="agpio_8h_html"><div class="ttname"><a href="gpio_8h.html">gpio.h</a></div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga16d25be75e16f0671d3e3185b0b59771"><div class="ttname"><a href="group__hardware__adc.html#ga16d25be75e16f0671d3e3185b0b59771">adc_set_round_robin</a></div><div class="ttdeci">static void adc_set_round_robin(uint input_mask)</div><div class="ttdoc">Round Robin sampling selector.</div><div class="ttdef"><b>Definition:</b> adc.h:150</div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga2a6fa32da04e65a027e14deaf32b8f10"><div class="ttname"><a href="group__hardware__adc.html#ga2a6fa32da04e65a027e14deaf32b8f10">adc_fifo_setup</a></div><div class="ttdeci">static void adc_fifo_setup(bool en, bool dreq_en, uint16_t dreq_thresh, bool err_in_fifo, bool byte_shift)</div><div class="ttdoc">Setup the ADC FIFO.</div><div class="ttdef"><b>Definition:</b> adc.h:232</div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga2b815e6730e8723a6d1d06d9ef8f31c0"><div class="ttname"><a href="group__hardware__adc.html#ga2b815e6730e8723a6d1d06d9ef8f31c0">adc_init</a></div><div class="ttdeci">void adc_init(void)</div><div class="ttdoc">Initialise the ADC HW.</div><div class="ttdef"><b>Definition:</b> adc.c:11</div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga333f7ca46a11241d96d0a4c24f0d4bb0"><div class="ttname"><a href="group__hardware__adc.html#ga333f7ca46a11241d96d0a4c24f0d4bb0">adc_set_clkdiv</a></div><div class="ttdeci">static void adc_set_clkdiv(float clkdiv)</div><div class="ttdoc">Set the ADC Clock divisor.</div><div class="ttdef"><b>Definition:</b> adc.h:204</div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga33f302059e05899d1709d6268d75972b"><div class="ttname"><a href="group__hardware__adc.html#ga33f302059e05899d1709d6268d75972b">adc_set_temp_sensor_enabled</a></div><div class="ttdeci">static void adc_set_temp_sensor_enabled(bool enable)</div><div class="ttdoc">Enable the onboard temperature sensor.</div><div class="ttdef"><b>Definition:</b> adc.h:161</div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga5d3b8875947df2f4ba022cb6aa40594b"><div class="ttname"><a href="group__hardware__adc.html#ga5d3b8875947df2f4ba022cb6aa40594b">adc_select_input</a></div><div class="ttdeci">static void adc_select_input(uint input)</div><div class="ttdoc">ADC input select.</div><div class="ttdef"><b>Definition:</b> adc.h:118</div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga5d50a24eb26da7fbc6ee9bc76723b09c"><div class="ttname"><a href="group__hardware__adc.html#ga5d50a24eb26da7fbc6ee9bc76723b09c">adc_run</a></div><div class="ttdeci">static void adc_run(bool run)</div><div class="ttdoc">Enable or disable free-running sampling mode.</div><div class="ttdef"><b>Definition:</b> adc.h:189</div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga61553375ecc9275fa14c6ff7792a1506"><div class="ttname"><a href="group__hardware__adc.html#ga61553375ecc9275fa14c6ff7792a1506">adc_fifo_get_blocking</a></div><div class="ttdeci">static uint16_t adc_fifo_get_blocking(void)</div><div class="ttdoc">Wait for the ADC FIFO to have data.</div><div class="ttdef"><b>Definition:</b> adc.h:286</div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga689d64744e7fe5284562569b24e9d624"><div class="ttname"><a href="group__hardware__adc.html#ga689d64744e7fe5284562569b24e9d624">adc_fifo_get</a></div><div class="ttdeci">static uint16_t adc_fifo_get(void)</div><div class="ttdoc">Get ADC result from FIFO.</div><div class="ttdef"><b>Definition:</b> adc.h:277</div></div>
<div class="ttc" id="agroup__hardware__adc_html_ga84b5f9054de9c00d51095c9bdefb2dca"><div class="ttname"><a href="group__hardware__adc.html#ga84b5f9054de9c00d51095c9bdefb2dca">adc_get_selected_input</a></div><div class="ttdeci">static uint adc_get_selected_input(void)</div><div class="ttdoc">Get the currently selected ADC input channel.</div><div class="ttdef"><b>Definition:</b> adc.h:137</div></div>
<div class="ttc" id="agroup__hardware__adc_html_gab15d6e804715935b4e9b5027a2940910"><div class="ttname"><a href="group__hardware__adc.html#gab15d6e804715935b4e9b5027a2940910">adc_gpio_init</a></div><div class="ttdeci">static void adc_gpio_init(uint gpio)</div><div class="ttdoc">Initialise the gpio for use as an ADC pin.</div><div class="ttdef"><b>Definition:</b> adc.h:95</div></div>
<div class="ttc" id="agroup__hardware__adc_html_gad637d97583f2c24e4159dc22bf17eaf2"><div class="ttname"><a href="group__hardware__adc.html#gad637d97583f2c24e4159dc22bf17eaf2">adc_fifo_drain</a></div><div class="ttdeci">static void adc_fifo_drain(void)</div><div class="ttdoc">Drain the ADC FIFO.</div><div class="ttdef"><b>Definition:</b> adc.h:297</div></div>
<div class="ttc" id="agroup__hardware__adc_html_gaf32d82a43103e6672048001f58d5f6fb"><div class="ttname"><a href="group__hardware__adc.html#gaf32d82a43103e6672048001f58d5f6fb">adc_read</a></div><div class="ttdeci">static uint16_t adc_read(void)</div><div class="ttdoc">Perform a single conversion.</div><div class="ttdef"><b>Definition:</b> adc.h:175</div></div>
<div class="ttc" id="agroup__hardware__adc_html_gaf8e363e63f40e00c169f7355c9668681"><div class="ttname"><a href="group__hardware__adc.html#gaf8e363e63f40e00c169f7355c9668681">adc_irq_set_enabled</a></div><div class="ttdeci">static void adc_irq_set_enabled(bool enabled)</div><div class="ttdoc">Enable/Disable ADC interrupts.</div><div class="ttdef"><b>Definition:</b> adc.h:310</div></div>
<div class="ttc" id="agroup__hardware__adc_html_gafa9793deea59c5cbfea147e0e9d895c3"><div class="ttname"><a href="group__hardware__adc.html#gafa9793deea59c5cbfea147e0e9d895c3">adc_fifo_get_level</a></div><div class="ttdeci">static uint8_t adc_fifo_get_level(void)</div><div class="ttdoc">Get number of entries in the ADC FIFO.</div><div class="ttdef"><b>Definition:</b> adc.h:268</div></div>
<div class="ttc" id="agroup__hardware__adc_html_gafdfd586e6c26ffe4759afaa3c3f95465"><div class="ttname"><a href="group__hardware__adc.html#gafdfd586e6c26ffe4759afaa3c3f95465">adc_fifo_is_empty</a></div><div class="ttdeci">static bool adc_fifo_is_empty(void)</div><div class="ttdoc">Check FIFO empty state.</div><div class="ttdef"><b>Definition:</b> adc.h:252</div></div>
<div class="ttc" id="agroup__hardware__base_html_ga625e737a57f12211cf1f634ca5095ae4"><div class="ttname"><a href="group__hardware__base.html#ga625e737a57f12211cf1f634ca5095ae4">hw_set_bits</a></div><div class="ttdeci">static __force_inline void hw_set_bits(io_rw_32 *addr, uint32_t mask)</div><div class="ttdoc">Atomically set the specified bits to 1 in a HW register.</div><div class="ttdef"><b>Definition:</b> address_mapped.h:135</div></div>
<div class="ttc" id="agroup__hardware__base_html_ga81b27e30abef56fe090d22fd8dfdbcc1"><div class="ttname"><a href="group__hardware__base.html#ga81b27e30abef56fe090d22fd8dfdbcc1">hw_write_masked</a></div><div class="ttdeci">static __force_inline void hw_write_masked(io_rw_32 *addr, uint32_t values, uint32_t write_mask)</div><div class="ttdoc">Set new values for a sub-set of the bits in a HW register.</div><div class="ttdef"><b>Definition:</b> address_mapped.h:171</div></div>
<div class="ttc" id="agroup__hardware__base_html_gafd1c089df868d987daf95870b501c2ed"><div class="ttname"><a href="group__hardware__base.html#gafd1c089df868d987daf95870b501c2ed">hw_clear_bits</a></div><div class="ttdeci">static __force_inline void hw_clear_bits(io_rw_32 *addr, uint32_t mask)</div><div class="ttdoc">Atomically clear the specified bits to 0 in a HW register.</div><div class="ttdef"><b>Definition:</b> address_mapped.h:145</div></div>
<div class="ttc" id="agroup__hardware__gpio_html_ga22f6b90c4c7e0013b4b5341de0a44fc4"><div class="ttname"><a href="group__hardware__gpio.html#ga22f6b90c4c7e0013b4b5341de0a44fc4">gpio_set_function</a></div><div class="ttdeci">void gpio_set_function(uint gpio, gpio_function_t fn)</div><div class="ttdoc">Select GPIO function.</div><div class="ttdef"><b>Definition:</b> gpio.c:38</div></div>
<div class="ttc" id="agroup__hardware__gpio_html_ga74a8c3e55185581bc3df335aea1d0fb8"><div class="ttname"><a href="group__hardware__gpio.html#ga74a8c3e55185581bc3df335aea1d0fb8">gpio_set_input_enabled</a></div><div class="ttdeci">void gpio_set_input_enabled(uint gpio, bool enabled)</div><div class="ttdoc">Enable GPIO input.</div><div class="ttdef"><b>Definition:</b> gpio.c:273</div></div>
<div class="ttc" id="agroup__hardware__gpio_html_gae57a625b7e0bcac6d596f35864ffc792"><div class="ttname"><a href="group__hardware__gpio.html#gae57a625b7e0bcac6d596f35864ffc792">gpio_disable_pulls</a></div><div class="ttdeci">static void gpio_disable_pulls(uint gpio)</div><div class="ttdoc">Disable pulls on specified GPIO.</div><div class="ttdef"><b>Definition:</b> gpio.h:337</div></div>
<div class="ttc" id="agroup__hardware__gpio_html_ggaf91b38a4d4e96c343bd16927c34936e0a3ec115257e1f1747abf60284362c5a04"><div class="ttname"><a href="group__hardware__gpio.html#ggaf91b38a4d4e96c343bd16927c34936e0a3ec115257e1f1747abf60284362c5a04">GPIO_FUNC_NULL</a></div><div class="ttdeci">@ GPIO_FUNC_NULL</div><div class="ttdoc">Select NULL as GPIO pin function.</div><div class="ttdef"><b>Definition:</b> io_bank0.h:41</div></div>
<div class="ttc" id="agroup__pico__platform_html_gab0d1ba75ceb64131e19f613d7a5313c9"><div class="ttname"><a href="group__pico__platform.html#gab0d1ba75ceb64131e19f613d7a5313c9">tight_loop_contents</a></div><div class="ttdeci">static __force_inline void tight_loop_contents(void)</div><div class="ttdoc">No-op function for the body of tight loops.</div><div class="ttdef"><b>Definition:</b> platform.h:80</div></div>
<div class="ttc" id="apico_8h_html"><div class="ttname"><a href="pico_8h.html">pico.h</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->

	<script src="main.js"></script>
</body>
</html>